<template>
  <div class="app">
    <h3>鱼塘陪玩</h3>
    <div class="recommendations">
      <el-image class="banner" :src="bannerImage"  style="height: 150px ;width: 100%; border-radius: 10px;"></el-image>
      </div>
    <div class="icon-container">
      <div class="icon" v-for="game in games" :key="game.id">
        <img :src="game.image" class="icon-image" @click="selectTab(game.id)" />
        <p class="icon-name">{{ game.gameType }}</p>
      </div>
    </div>
    <div class="info-notice">
      <div class="content">
        <span class="title">信息公告</span>
        <p class="text">快速派单，极速响应</p>
        <p class="text">给陪玩推送提醒，每日首页免费派单</p>
      </div>
      <button class="check-btn" @click="checkNotice">立即查看</button>
    </div>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="王者荣耀" name="second">
          <div class="player-card" v-for="p in player" v-if="p.gid==1">
            <el-image :src="p.photo" style="width: 100px;height: 100px;"></el-image>
            <div class="player-info">
              <h3>{{ p.name}}</h3>
              <p>{{ p.good }}</p>
              <div class="rating">
                <span>评分: {{ p.score }}</span>
              </div>
              <el-image :src="p.gameImage" style="width: 20px;height: 20px;"></el-image>
              <span class="games">{{ p.gamesType }}</span>
              <button @click="hirePlayer(p.gid)">找ta陪玩</button>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="永劫无间" name="third">
          <div class="player-card" v-for="p in player" v-if="p.gid==4">
            <el-image :src="p.photo" style="width: 100px;height: 100px;"></el-image>
            <div class="player-info">
              <h3>{{ p.name}}</h3>
              <p>{{ p.good }}</p>
              <div class="rating">
                <span>评分: {{ p.score }}</span>
              </div>
              <el-image :src="p.gameImage" style="width: 20px;height: 20px;"></el-image>
              <span class="games">{{ p.gamesType }}</span>
              <button @click="hirePlayer(p.gid)">找ta陪玩</button>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="和平精英" name="fourth">
          <div class="player-card" v-for="p in player" v-if="p.gid==2">
            <el-image :src="p.photo" style="width: 100px;height: 100px;"></el-image>
            <div class="player-info">
              <h3>{{ p.name}}</h3>
              <p>{{ p.good }}</p>
              <div class="rating">
                <span>评分: {{ p.score }}</span>
              </div>
              <el-image :src="p.gameImage" style="width: 20px;height: 20px;"></el-image>
              <span class="games">{{ p.gamesType }}</span>
              <button @click="hirePlayer(p.gid)">找ta陪玩</button>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="英雄联盟" name="first">
          <div class="player-card" v-for="p in player" v-if="p.gid==3">
            <el-image :src="p.photo" style="width: 100px;height: 100px;"></el-image>
            <div class="player-info">
              <h3>{{ p.name}}</h3>
              <p>{{ p.good }}</p>
              <div class="rating">
                <span>评分: {{ p.score }}</span>
              </div>
              <el-image :src="p.gameImage" style="width: 20px;height: 20px;"></el-image>
              <span class="games">{{ p.gamesType }}</span>
              <button @click="hirePlayer(p.gid)">找ta陪玩</button>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    <van-tabbar route>
      <van-tabbar-item icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item replace to="/NotificationList" icon="setting-o">消息</van-tabbar-item>
      <van-tabbar-item replace to="/mine" icon="friends-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      searchQuery: '',
      bannerImage: 'https://ts1.cn.mm.bing.net/th/id/R-C.e6a4f47c4315edf8c6b441e904fe3224?rik=mnbUPRg1m75uGQ&riu=http%3a%2f%2fgame.gtimg.cn%2fimages%2fyxzj%2fcoming%2fv2%2fskins%2fimage%2f20200622%2f93e57fe8a1e0ab8192f4daf4564520bf.jpg&ehk=5bSC1Y7AKMA6vQ1vGp0c2%2fiE4WZD5%2fYVq9aBEdo1dJY%3d&risl=&pid=ImgRaw&r=0', // 替换为实际的 banner 图片地址
      recommendedGames: [],
      hasMore: true,
      loading: false,
      error: null,
      currentPage: 1,
      games: [],
      navigationData: [],
      activeTab: null,
      showMoreOptions: false,
      from:{},
      player: {},
    };
  },
  mounted() {
      this.searchGames();
      this.servePlayer();
  },
  methods: {
    hirePlayer(gid){
      this.$router.push({path: '/accompany', query: {gid: JSON.stringify(gid)}})
    },
    checkNotice() {
      this.$router.push('/inform')
    },
    xx(){
      this.$router.push('/NotificationList')// 跳转到消息页面
    },
    selectTab(id){
      this.$router.push({path: '/one', query: {id: JSON.stringify(id)}})
    },
    servePlayer() {
      axios.post('http://localhost:8083/play/list', this.player).then(response => {
        this.player = response.data.data;
        console.log(this.player)
      }).catch(error => {
        console.error('Error fetching player:', error);
        this.error = error;
    })
    },
    searchGames(){
      axios.post('http://localhost:8082/games/list').then(response => {
        this.games = response.data.data;
      }).catch(error => {
        console.error('Error fetching games:', error);
        this.error = error;
      })
    }
  }
};
</script>

<style scoped>

.player-card {
            display: flex;
            align-items: center;
            border: 1px solid #ccc;
            padding: 10px;
}
.player-info {
            flex: 1;
          }

.rating {
  margin-top: 5px;
}

.games {
  margin-top: 5px;
}

button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}
button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}
.info-notice {
          display: flex;
          justify-content: space-between;
          align-items: center;
          border: 1px solid #ccc;
          padding: 10px;
        }

.content {
  display: flex;
  flex-direction: column;
}

.title {
  font-weight: bold;
  margin-bottom: 5px;
}

.text {
  margin: 0;
}

.check-btn {
background-color: #007bff;
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
         }
.navigation-bar {
display: flex;
background-color: #fff;
border-bottom: 1px solid #ccc;
}
.navigation-bar div {
padding:4px;
cursor: pointer;
}
.active-tab {
background-color: lightblue;
}
.more-option {
margin-left: auto;
padding: 10px 10px;
cursor: pointer;
}
.more-options-list {
position: absolute;
background-color: #fff;
border: 1px solid #ccc;
display: none;
}
.icon-container {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  //background-color: #f8f9fa; /* 背景颜色 */
  border-radius: 10px; /* 圆角边框 */
}

.icon {
  text-align: center;
  flex: 1; /* 每个图标占相同宽度 */
  margin: 0 5px; /* 图标间距 */
}

.icon-image {
  width: 80px; /* 图标大小 */
  height: 80px; /* 图标大小 */
  border-radius: 10px; /* 圆角 */
  background-color: #e0e0e0; /* 备用颜色 */
}

.icon-name {
  margin-top: 5px; /* 标题与图标的距离 */
  font-size: 14px; /* 标题字体大小 */
  color: #333; /* 字体颜色 */
}
.banner {
  margin-top: 10px;
}
.app {
  margin-top: -60px;
  font-family: Arial, sans-serif;
  //background-color: #f8f9fa;
  padding: 20px;
  height: 1000px;
}

.header {
  display: flex;
  margin-bottom: 20px;
}

.header input {
  flex: 1;
  padding: 10px;
  border: 1px solid #d1d1d1;
  border-radius: 5px;
}

.header button {
  padding: 10px;
  margin-left: 10px;
  border: none;
  background-color: #007bff;
  color: white;
  border-radius: 5px;
}

.banner {
  margin-top: 10px;
}

.banner img {
  width: 100%;
  border-radius: 10px;
}

.recommendations {
  //background-color: #ffffff;
  //padding: 20px;
  border-radius: 10px;
}

.game-card {
  display: flex;
  padding: 10px;
  border: 1px solid #d1d1d1;
  border-radius: 5px;
  margin-bottom: 10px;
}

.game-card img {
  width: 80px;
  border-radius: 5px;
  margin-right: 10px;
}

.game-info {
  flex: 1;
}

.recommendations button {
  margin-top: 10px;
  padding: 10px;
  border: none;
  background-color: #007bff;
  color: white;
  border-radius: 5px;
}

.error {
  color: red;
  margin-top: 10px;
}
</style>
